<?php
include 'lib.php';
ini_set('display_errors', 1);

$artists = Database::query("SELECT * FROM `artists` ORDER BY `lastfm_updated` ASC LIMIT 50");
ini_set('max_execution_time', 500);

// Include the API
require 'lib/lastfmapi/lastfmapi.php';


// Put the auth data into an array
$authVars = array(
	'apiKey' => '5e6a9eb30f4dd80779c96113d27b5a25',
    'secret' => '1e0a1293702d76020603e622453b620b'
);
$config = array(
	'enabled' => true,
	'path' => 'lib/lastfmapi/',
	'cache_length' => 1800
);
// Pass the array to the auth class to eturn a valid auth
$auth = new lastfmApiAuth('setsession', $authVars);

// Call for the album package class with auth data
$apiClass = new lastfmApi();
$artistClass = $apiClass->getPackage($auth, 'artist', $config);

foreach ($artists as $artist)
{
    // Setup the variables
    $methodVars = array(
    	'artist' => $artist['name'],
    );
    
    if ( $info = $artistClass->getInfo($methodVars) ) {
    	echo '<b>Data Returned</b>';
        print_r($info);
    }
    else {
    	continue;
    }

    $description = Database::escape(strip_tags($info['bio']['content']));
    $summary = Database::escape(strip_tags($info['bio']['summary']));
    $mb_id = Database::escape($info['mbid']);
    $display_name = Database::escape($info['name']);
    $lasfm_url = Database::escape($info['url']);
    
    Database::insert("UPDATE artists SET 
        `display_name` = '$display_name', 
        `description` = '$description', 
        `summary` = '$summary', 
        `mb_id` = '$mb_id', 
        `lastfm_url` = '$lasfm_url',
        `lastfm_updated` = NOW()
        WHERE `id` = $artist[id]");
       

}
?>